import React from 'react'
import { connect } from 'dva'
import { Tabs } from 'antd'
import Departmentpage from './departmentpage'
import Organizationpage from './organizationpage'
import Modal from './modal'
import AddModal from './addModal'

const TabPane = Tabs.TabPane;

const Organization = ({location,dispatch,organization,loading}) => {
	const {list,pagination1,menu,visible,visible1,info,orginList,isNew,params,depId} = organization
	const callback = key =>{
		// console.log(key)
	}
	const organizationProps = {
		loading:loading.effects['organization/list'],
		list,
		pagination1,
		showDetails(id,boolean){
			dispatch({
				type:'organization/info',
				payload:{
					id:id,
					isNew:boolean
				}
			})
		},
		showModals(boolean){
			dispatch({
				type:'organization/showModal',
				payload:boolean
			})
		},
		deleteOrganization(id){
			dispatch({
				type:'organization/delete',
				payload:{
					id:id
				}
			})
		},
		removeOrganization(id){
			dispatch({
				type:'organization/remove',
				payload:{
					childId:id
				}
			})	
		},
		onPageChange (page) {
          const { query, pathname } = location
          dispatch({
                type: 'organization/list',
                payload: {
                  ...params,
                  page: page.current,
                	  pageSize: page.pageSize,
                }
              })
	       },
	    onSearch(params) {
		    	dispatch({
		    		type:'organization/list',
		    		payload:{
		    			...params
		    		}
		    	})
	    },
	    showOrganization(){
	    		dispatch({
	    			type:'organization/organList',
	    			payload:{
	    				
	    			}
	    		})
	    },
	    showAllOrganization(){
	    		dispatch({
	    			type:'organization/organList',
	    			payload:{
	    				
	    			}
	    		})
	    }
	}
	const depaermentProps = {
		loading:loading.effects['organization/list'],
		list,
		depId,
		pagination1,
		deleteDep(id){
			dispatch({
				type:'organization/deleteDep',
				payload:{
					id:id
				}
			})
		},
		showModal(id){
			dispatch({
				type:'organization/showAddModal',
				payload:id
			})
		},
		addDep(payload){
			dispatch({
				type:'organization/addDep',
				payload:{
					...payload
				}
			})
		},
		onSearch(params) {
		    	dispatch({
		    		type:'organization/list',
		    		payload:{
		    			...params
		    		}
		    	})
	    },
	}
	const modalProps = {
		info,
		visible,
		isNew,
		orginList,
		onCancel(){
			dispatch({
				type:'organization/hideModal',
				payload:{
					
				}
			})
		},
		onUpdate(data){
			dispatch({
//				type:'organization/addChildOrganization',
				type:'organization/updateOrganization',
				payload:{
					...data
				}
			})
		},
		
		onNew(data){
			dispatch({
				type:'organization/newOrganization',
				payload:{
					...data
				}
			})
		}
	}
	const addModal = {
		visible1,
		depId,
		onCancel(){
			dispatch({
				type:'organization/hideAddModal',
				payload:{
					
				}
			})
		},
		addDeps(payload){
			dispatch({
				type:'organization/addDep',
				payload:{
					...payload
				}
			})
		}
	}
	
	return(
		<div>
			<Tabs defaultActiveKey="0" onChange={callback}>
				<TabPane tab="机构管理" key="0">
		            <Organizationpage {...organizationProps}/>
		            {visible ? <Modal {...modalProps}/>:''}
		         </TabPane>
		         
		         <TabPane tab="部门管理" key="1">
		           	<Departmentpage {...depaermentProps}/>
		           	{visible1 ? <AddModal {...addModal}/>:''}
		         </TabPane>
			</Tabs>
		</div>
	)
}

export default connect(({organization,loading}) => ({organization,loading}))(Organization)
